<?php 
require_once dirname(__FILE__) . '/../../../incls/php/dbutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/miscutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/config.php';

session_name(SESSION);
session_start();

if (!isset($_SESSION['index' . USER])) {
  echo "
  <script>
  parent.location.href = 'http://" . URL . "?i=" . LOGIN_ID . "&url=' + encodeURIComponent(parent.document.URL);
  </script>
  ";
  die('');
}

$myPdo = DbUtils::createPdoInst();
$page_id = MiscUtils::getParam('i', 0);
$script = MiscUtils::getParam('script', 'index');
$status = MiscUtils::getParam('status', 1);

$cond_vals = new stdClass();
$cond_vals->c = 't.customer_id = :v1 AND is_paid = 0 AND is_cancel = 0';
$cond_vals->v = array(':v1' => $_SESSION['index' . USER]->id);
$opt = new stdClass();
$opt->select_expr = 'COUNT(t.id) AS _count';
$unpaid = DbUtils::get($myPdo, TABLE_NAME_PREFIX_PLUGIN . 'ecom_order', $cond_vals, NULL, NULL, NULL, NULL, $opt)->d[0]->_count;

$cond_vals = new stdClass();
$cond_vals->c = 't.customer_id = :v1 AND is_paid = 1 AND is_delivered = 0 AND is_cancel = 0';
$cond_vals->v = array(':v1' => $_SESSION['index' . USER]->id);
$opt = new stdClass();
$opt->select_expr = 'COUNT(t.id) AS _count';
$paid = DbUtils::get($myPdo, TABLE_NAME_PREFIX_PLUGIN . 'ecom_order', $cond_vals, NULL, NULL, NULL, NULL, $opt)->d[0]->_count;

$cond_vals = new stdClass();
$cond_vals->c = 't.customer_id = :v1 AND is_delivered = 1 AND date_deliver >= :v2 AND is_cancel = 0';
$cond_vals->v = array(':v1' => $_SESSION['index' . USER]->id, ':v2' => date('Y-m-d', time() - (864000)));
$opt = new stdClass();
$opt->select_expr = 'COUNT(t.id) AS _count';
$shipped = DbUtils::get($myPdo, TABLE_NAME_PREFIX_PLUGIN . 'ecom_order', $cond_vals, NULL, NULL, NULL, NULL, $opt)->d[0]->_count;

$cond_vals = new stdClass();
$cond_vals->c = 't.customer_id = :v1 AND is_delivered = 1 AND date_deliver < :v2 AND is_cancel = 0';
$cond_vals->v = array(':v1' => $_SESSION['index' . USER]->id, ':v2' => date('Y-m-d', time() - (864000)));
$opt = new stdClass();
$opt->select_expr = 'COUNT(t.id) AS _count';
$closed = DbUtils::get($myPdo, TABLE_NAME_PREFIX_PLUGIN . 'ecom_order', $cond_vals, NULL, NULL, NULL, NULL, $opt)->d[0]->_count;
?>